package com.campus.campusdelivery.controller;

import com.campus.campusdelivery.dto.ApiResponse;
import com.campus.campusdelivery.dto.OrderDto;
import com.campus.campusdelivery.dto.StatsDto;
import com.campus.campusdelivery.service.AdminService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/admin")
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class AdminController {
    
    private final AdminService adminService;
    
    @GetMapping("/stats")
    public ApiResponse<StatsDto> getSystemStats() {
        try {
            StatsDto stats = adminService.getSystemStats();
            return ApiResponse.success(stats);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
    
    @GetMapping("/users")
    public ApiResponse<Object> getAllUsers() {
        try {
            // TODO: 实现获取所有用户
            return ApiResponse.success("获取用户列表成功", null);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
    
    @GetMapping("/merchants")
    public ApiResponse<Object> getAllMerchants() {
        try {
            // TODO: 实现获取所有商家
            return ApiResponse.success("获取商家列表成功", null);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
    
    @GetMapping("/orders")
    public ApiResponse<Object> getAllOrders() {
        try {
            // TODO: 实现获取所有订单
            return ApiResponse.success("获取订单列表成功", null);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
    
    @GetMapping("/today-stats")
    public ApiResponse<StatsDto> getTodayStats() {
        try {
            StatsDto stats = adminService.getTodayStats();
            return ApiResponse.success(stats);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
    
    @GetMapping("/recent-orders")
    public ApiResponse<List<OrderDto>> getRecentOrders(@RequestParam(defaultValue = "10") int limit) {
        try {
            List<OrderDto> orders = adminService.getRecentOrders(limit);
            return ApiResponse.success(orders);
        } catch (Exception e) {
            return ApiResponse.error(e.getMessage());
        }
    }
}
